function cfdReadFlowFacesFile(facesFileDirectory)
%--------------------------------------------------------------------------
%  Written by LiuHaHa @ NWPU, 2022 01 
%  Contact me at: liuzhikan@mail.nwpu.edu.cn
%==========================================================================
% Routine Description:
%   This function reads faces file in mesh
%--------------------------------------------------------------------------
global cfdFlow;
global slvpara;

% Open faces file in read mode
ffid = fopen(facesFileDirectory, 'r');

% Initialize header
header = cell(0);

% Scan/Read header
while ~feof(ffid)         
    tline = fgetl(ffid);
    
    % Skip empty lines
    tline = cfdSkipEmptyLines(ffid, tline);

    % Skip macro-commented section
    tline = cfdSkipMacroComments(ffid, tline);
    
    % Skip commented lines
    tline = cfdSkipCommentedLine(ffid, tline);    

    % read header block
    if cfdContains(tline, 'FoamFile')   
        if isempty(header)
            header = cfdReadDictionary(ffid, 'FoamFile');
        else
            break;
        end
    else
        if ~isempty(header)
            break;
        end        
    end
end

% Skip to number of points 
tline = cfdSkipEmptyLines(ffid, tline);  

% Skip to number of faces        
C = textscan(tline,'%d',1);
while isempty(C{1})        
    tline = fgetl(ffid);
    if isempty(tline)
        continue;
    end

    if feof(ffid)
       error('faces list not there!!'); 
    end
    C = textscan(tline,'%d',1);
end   
if(slvpara.ND == 2)
    numberOfFaces = C{1}-cfdFlow.mesh.numberOfEmptyFaces;
else
    numberOfFaces = C{1};
end 
% Initialize
faceNodes = cfdLabelListList(numberOfFaces);    

% Reach list opening paranthesis
c = fscanf(ffid, '%c', 1);  
while ~strcmp(c, '(')
    c = fscanf(ffid, '%c', 1);  
end

% Read items in list
for item=1:numberOfFaces
    numberOfPoints = fscanf(ffid, '%d', 1);
    
    % Reach sub list opening paranthesis
    c = fscanf(ffid, '%c', 1);  
    while ~strcmp(c, '(')
        c = fscanf(ffid, '%c', 1);  
    end    
    
    for iPoint=1:numberOfPoints
        faceNodes{item} = [faceNodes{item} fscanf(ffid, '%d', 1) + 1];
    end
    
    % Reach sub list closing paranthesis
    c = fscanf(ffid, '%c', 1);  
    while ~strcmp(c, ')')
        c = fscanf(ffid, '%c', 1);  
    end      
end

% Close
fclose(ffid);

% Save and Store
meshTemp = cfdFlow.mesh;
%
if(slvpara.ND == 2)
    for i=1:numberOfFaces
        temp = faceNodes{i};
        faceNodes{i} = temp(1:2);
    end
end
meshTemp.faceNodes = faceNodes;
meshTemp.numberOfFaces = numberOfFaces;

cfdFlow.mesh = meshTemp;

